package gov.kqqzyyy.monkey.pharmacyscreen.code.adapter;

import android.content.Context;
import androidx.core.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import gov.kqqzyyy.monkey.pharmacyscreen.R;
import gov.kqqzyyy.monkey.pharmacyscreen.code.mytools.MyStringUtil;
import gov.kqqzyyy.monkey.pharmacyscreen.code.object.HJBR;

/**
 * Created by Monkey on 2017/11/23.
 * 西药房叫号窗口 适配器
 */

public class MyJKCKAdapter extends BaseAdapter {

    private List<HJBR> list;
    private LayoutInflater inflater;
    private Context mContext;
    private int textColor;

    private int PDHM = -1;

    public MyJKCKAdapter(Context context) {
        mContext = context;
        inflater = LayoutInflater.from(mContext);
        textColor = ContextCompat.getColor(mContext, R.color.colorBlack);
    }

    public void setList(List<HJBR> showList) {
        this.list = showList;
        notifyDataSetChanged();
    }

    public void setPDHM(int PDHM) {
        this.PDHM = PDHM;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (list != null) {
            return list.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if (list != null && list.get(position) != null) {
            return list.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_ckjh_patient, parent, false);
            holder.infoText = convertView.findViewById(R.id.item_jhck_info);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        HJBR hjbr = list.get(position);
        if (hjbr != null) {
            String text = "请 " + MyStringUtil.doFormatXH(String.valueOf(hjbr.getPdhm())) + " 号 " + MyStringUtil.doHideName(hjbr.getBrxm()) + " 到 " + hjbr.getCkmc() + " 取药 ";
            holder.infoText.setText(text);
            int thisColor;
            if (hjbr.getPdhm() == PDHM) {
                thisColor = ContextCompat.getColor(mContext, R.color.colorOrange);
            } else {
                thisColor = textColor;
            }
            holder.infoText.setTextColor(thisColor);
        }

        return convertView;
    }

    private class ViewHolder {
        TextView infoText;
    }
}
